package net.akkz.dao.impl;

import java.util.ArrayList;

import net.akkz.dao.ImgViewGoodDao;
import net.akkz.dbFactory.Session;
import net.akkz.exception.BuildClassError;
import net.akkz.exception.SQLExcuteException;
import net.akkz.model.ImgViewGood;

public class ImgViewGoodDaoImpl implements ImgViewGoodDao
{

	@Override
	public void addImgViewGood(Session session, ImgViewGood imgViewGood) throws SQLExcuteException
	{
		String sql = "insert into imgviewgood(imgviewid, studentid) values(?, ?)";

		Object[] values = new Object[2];
		values[0] = imgViewGood.getImgviewid();
		values[1] = imgViewGood.getStudentid();
		
		session.excute(sql, values);
	}

	@Override
	public ArrayList<ImgViewGood> findImgViewByImgViewId(Session session, int imgViewId) throws SQLExcuteException, BuildClassError
	{
		String sql = "select * from imgviewgood where imgviewid = ?";
		
		Object[] values = new Object[1];
		values[0] = imgViewId;
		
		return session.find(sql, values, ImgViewGood.class);
	}

	@Override
	public ArrayList<ImgViewGood> findImgViewByStudentId(Session session, int studentId) throws SQLExcuteException, BuildClassError
	{
		String sql = "select * from imgviewgood where studentid = ?";
		
		Object[] values = new Object[1];
		values[0] = studentId;
		
		return session.find(sql, values, ImgViewGood.class);
	}

	@Override
	public void deleteImgViewId(Session session, ImgViewGood imgViewGood) throws SQLExcuteException
	{
		String sql = "delete from imgviewgood where imgviewid=? and studentid=?";

		Object[] values = new Object[2];
		values[0] = imgViewGood.getImgviewid();
		values[1] = imgViewGood.getStudentid();
		
		session.excute(sql, values);
	}

	@Override
	public boolean checkImgViewGood(Session session, ImgViewGood imgViewGood) throws SQLExcuteException, BuildClassError
	{
		String sql = "select * from imgviewgood where imgviewid=? and studentid=?";
		
		Object[] values = new Object[2];
		values[0] = imgViewGood.getImgviewid();
		values[1] = imgViewGood.getStudentid();
		
		ImgViewGood imgViewGoodModel = session.get(sql, values, ImgViewGood.class);
		
		return imgViewGoodModel != null;
	}

}
